<?php

/**
 * 后台公用控制器
 * @author 艾逗笔<http://idoubi.cc>
 */
namespace Admin\Controller;
use Common\Controller\CommonController;
Vendor('qiniusdk.autoload');
use \Qiniu\Auth;
use \Qiniu\Storage\UploadManager;
use Qiniu\Storage\BucketManager;
class BaseController extends CommonController {
	
	// 初始化
	public function __construct() {
		parent::__construct();
		/*
		if (empty($this->user_access) || empty($this->user_access['admin'])) {
			$this->error('你没有访问此模块的权限');
		}
		*/
		global $_G;
		$topnav = [];
		$topnav[] = array(
			'title' => '首页',
			'url' => U('Admin/Index/index'),
			'class' => CONTROLLER_NAME == 'Index'?'active':''
		);
		$topnav[] = array(
			'title' => '专家团队',
			'url' => U('Admin/Expert/index'),
			'class' => CONTROLLER_NAME == 'Expert'?'active':''
		);
		$topnav[] = array(
			'title' => '新闻资讯',
			'url' => U('Admin/New/index'),
			'class' => CONTROLLER_NAME == 'New'?'active':''
		);
		$topnav[] = array(
			'title' => '培训商城',
			'url' => U('Admin/Shop/index'),
			'class' => CONTROLLER_NAME == 'Shop'?'active':''
		);
		$topnav[] = array(
			'title' => '招商合作',
			'url' => U('Admin/Investment/index'),
			'class' => CONTROLLER_NAME == 'Investment'?'active':''
		);		
		switch (CONTROLLER_NAME) {
			case 'Index':
				$sidenav = array(
					array(
						'title' => '导航管理',
						'url' => U('Index/Homepagemanagement'),
						'class' => 'icon icon-home'
					),
					array(
						'title' => '轮播图管理',
						'url' => U('Index/picture'),
						'class' => 'icon icon-at'
					),
					array(
						'title' => '友情链接管理',
						'url' => U('Index/friendship'),
						'class' => 'icon icon-triangle'
					),
					array(
						'title' => '备案信息',
						'url' => U('Index/keep'),
						'class' => 'icon icon-setting'
					),
					array(
						'title' => '二维码',
						'url' => U('Index/code'),
						'class' => 'icon icon-23'
					)
				);
				break;
			case 'Expert':
				$sidenav = array(
					array(
						'title' => '专家管理',
						'url' => U('Admin/Expert/index'),
						'class' => 'icon icon-home'
					)
				);
				break;
				case 'New':
				$sidenav = array(
					array(
						'title' => '新闻管理',
						'url' => U('Admin/New/index'),
						'class' => 'icon icon-home'
					)
				);
				break;
				case 'Shop':
				$sidenav = array(
					array(
						'title' => '产品管理',
						'url' => U('Admin/Shop/index'),
						'class' => 'icon icon-home'
					),
					array(
						'title' => '分类管理',
						'url' => U('Admin/Shop/type'),
						'class' => 'icon icon-home'
					)
				);
				break;
				
			default:
				# code...
				break;
		}
		/*
		$sidenav = array(
			array(
				'title' => '导航管理',
				'url' => U('Index/Homepagemanagement'),
				'class' => 'icon icon-home'
			),
			array(
				'title' => '轮播图管理',
				'url' => U('Index/picture'),
				'class' => 'icon icon-at'
			),
			array(
				'title' => '友情链接管理',
				'url' => U('Index/friendship'),
				'class' => 'icon icon-triangle'
			),
			array(
				'title' => '备案信息',
				'url' => U('Index/keep'),
				'class' => 'icon icon-setting'
			),
			array(
				'title' => '二维码',
				'url' => U('Index/code'),
				'class' => 'icon icon-code'
			),
			/*
			array(
				'title' => '用户权限管理',
				'url' => 'javascript:;',
				'class' => 'icon icon-user',
				'attr' => 'data="icon"',
				'children' => array(
					array(
						'title' => '用户管理',
						'url' => U('User/lists'),
						'class' => $this->controller == 'user' ? 'active' : ''
					),
					array(
						'title' => '角色管理',
						'url' => U('Role/lists'),
						'class' => $this->controller == 'role' ? 'active' : ''
					),
					// array(
					// 	'title' => '权限节点管理',
					// 	'url' => U('Node/lists'),
					// 	'class' => ''
					// )
				),
			),
			array(
				'title' => '账号管理',
				'url' => 'javascript:;',
				'class' => 'icon icon-reply',
				'attr' => 'data="icon"',
				'children' => array(
					array(
						'title' => '账号列表',
						'url' => U('Mp/lists'),
						'class' => $this->controller == 'mp' ? 'active' : ''
					),
					array(
						'title' => '账号套餐',
						'url' => U('MpGroup/lists'),
						'class' => $this->controller == 'mpgroup' ? 'active' : ''
					)
				)
			),
			array(
				'title' => '扩展管理',
				'url' => U('Addons/lists'),
				'class' => 'icon icon-job',
                'children' => [
                    [
                        'title' => '功能插件',
                        'url' => U('Addons/lists'),
                        'class' => $this->controller == 'addons' ? 'active' : ''
                    ]
                ]
			)
			*/
		//);
		
		$this->assign('sidenav', $sidenav);
		$this->assign('topnav', $topnav);
		$this->assign('product_info', $_G['product_info']);
		$this->assign('system_settings', $_G['system_settings']);
		$this->assign('user_info', $this->user_info);
	}
	
	/**
	 * 初始化
	 */
	public function _initialize() {
		parent::_initialize();
	}
	  //获取七牛上传的必要参数
    public function qiniu_token()
    {
        
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        header('Access-Control-Allow-Methods: GET, POST, PUT');
        $bucket = C('bucket');
        $accessKey = C('as');
        $secretKey = C('ak');
        $domain = C('domain');
        $auth = new Auth($accessKey, $secretKey);
        $upToken = $auth->uploadToken($bucket);
        $ret = array(
            'uptoken' => $upToken,
            'domain' => $domain
        );
        $this->ajaxReturn($ret);
    }
}


?>